package com.kadron.entity;

import java.io.Serializable;

import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import org.hibernate.validator.NotNull;

@Entity
@DiscriminatorValue(value = "0")
public class DiscountItem extends AbstractDiscountSource implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8619469243284599427L;
	
	private Item item;
	
	public DiscountItem() {
		super();
	}

	public DiscountItem(Discount discount, Item item) {
		super(discount, 0);
		this.item = item;
	}

	@NotNull
	@ManyToOne(targetEntity = Item.class)
	@JoinColumn(name = "item_id", updatable = false)
	public Item getItem() {
		return item;
	}
	
	public void setItem(Item item) {
		this.item = item;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (int) (id ^ (id >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		DiscountItem other = (DiscountItem) obj;
		if (id != other.id)
			return false;
		return true;
	}

}
